/*
 * Reversr Interger
 * 
 * Reverse digits of an integer.
 * Example1: x = 123, return 321
 * Example2: x = -123, return -321
 */

#include <vector>
#include <iostream>
using namespace std;

 int power(int a ,int b)
  {
      int result=1;
      while(b>0)
      {
          result = result*a;
          b--;
      }
      return result;
  }
  int reverse(int x) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
     
      vector<int> vect;
      int r ; 
      int value=x;
      if(x<0)
      {
          value=value*(-1);
          
      }
      for(int temp=value;temp>0; temp = temp/10)
      {
         
          r = temp%10;
          
          vect.push_back(r);
          //cout<<' '<<r;
      }

      
      int length = vect.size();
      int result=0;
      for(int i=0;i<length;i++)
      {
          result =result+ vect[i]*power(10,length-1-i);
          cout<<' '<<vect[i];
      }
      
      if(x<0)
      {
          result=result*(-1);
      }
      return result;
    }
  
 
  
  void TestReverse()
  {
     
      cout<<reverse(-321);
  }
